package com.web.page;

import com.web.annotations.Copy;
import com.web.annotations.PageElement;
import com.web.annotations.PageUrl;
import com.web.imp.AbstractWebPage;
import com.web.lang.Language;
import com.web.lang.LanguageConfig;
import com.web.model.element.WebButton;
import com.web.model.element.WebCheckBox;
import com.web.model.element.WebLink;
import com.web.model.element.WebTextField;

@PageUrl("/user/login")
public class Login extends AbstractWebPage{

	@Copy(id = "title_login")
	public static String TITLE;
	
	@Copy(id = "user_o_pass_invalid")
	public static String INCORRECT_EMAIL_OR_PASSWORD;
	
	@Copy(id = "isEmpty")
	public static String BLANK_FIELDS;
	
	
	@PageElement(id = "user")
	private WebTextField userField;
	
	@PageElement(id = "password")
	private WebTextField passwordField;
	
	@PageElement(id = "add_login")
	private WebButton startSession;
	
	@PageElement(id = "sesion_automatica")
	private WebCheckBox stayLoggedIn;
	
	@PageElement(id = "logo")
	private WebLink logo;
	
	public String getUrl(){
		
		Language language = LanguageConfig.getLanguage();
		this.url += "?lang=" + language;
		
		return this.url;
	}
	
	public Index login(String user, String password){
		
		userField.sendKeys(user);
		passwordField.sendKeys(password);
		startSession.click();
		
		return browser.open(Index.class);
	}
	
	public void loginError(String user, String password){
		
		userField.sendKeys(user);
		passwordField.sendKeys(password);
		startSession.click();
	}	
	
	public Index loginAndStayLogged(String user, String password){
		
		userField.sendKeys(user);
		passwordField.sendKeys(password);
		stayLoggedIn.check();
		startSession.click();
		
		return browser.open(Index.class);
	}
	
	public void loginAndStayLoggedError(String user, String password){
		
		userField.sendKeys(user);
		passwordField.sendKeys(password);
		stayLoggedIn.check();
		startSession.click();
	}	
	
	public void clickLogoToHome(){
		logo.click();
	}
}
